package com.xuetang9.fujian.donamicproxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @author: fujian
 * @description: 动态代理登录
 * 1、实现invoke方法，就是拦截的方法，需要真正做事情的对象
 * @date: 2021/5/1 10:14
 * @version: V1.0
 * @package: com.xuetang9.fujian.donamicproxy
 **/
public class LoginInvocationHandler implements InvocationHandler {
    private Object targetObj;

    public LoginInvocationHandler(Object targetObj) {
//        真正做事的对象
        this.targetObj = targetObj;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        System.out.println("当前拦截的方法：" + method.getName());
        String str = "";
        for (Object arg : args) {
            str += arg + ",";
        }
        System.out.println("参数列表：" + str);
        System.out.println(method.getName() + "方法调用前");
        Object result = method.invoke(targetObj, args);
        System.out.println(method.getName() + "方法调用后");
        return result;
    }
}
